/**
 * @Author: wangliuyang
 * @Date: 2021/9/6 11:23
 * @Description:27. 移除元素
 */
public class Solution_27 {
    public int removeElement(int[] nums, int val) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right){
            if (nums[left] == val){
                swap(nums,left,right--);
            }else {
                left++;
            }
        }
        return left;
    }
    public void swap(int[] arrs,int ia,int ib){
        if (ia == ib) return;
        arrs[ia] = arrs[ia] ^ arrs[ib];
        arrs[ib] = arrs[ia] ^ arrs[ib];
        arrs[ia] = arrs[ia] ^ arrs[ib];
    }
}
